﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

using SqlHelper;
using System.Data;
using System.Data.SqlClient;

namespace DAL
{
    public class ReconcileDatabase
    {
        /// <summary>
        /// 执行对明细帐操作
        /// </summary>
        /// <param name="detail">实体对象</param>
        /// <returns></returns>
        public static bool PerformReconcile(string startDate,string endDate,string bankCode)
        {
            bool ret = true;
            SqlConnection conn = null;

            DateTime startDt = Convert.ToDateTime(startDate.Substring(0, 4) + "-" + startDate.Substring(4, 2) + "-" + startDate.Substring(6, 2) + " " +
                                                  startDate.Substring(8, 2) + ":" + startDate.Substring(10, 2) + ":" + startDate.Substring(12, 2));
            DateTime endDt = Convert.ToDateTime(endDate.Substring(0, 4) + "-" + endDate.Substring(4, 2) + "-" + endDate.Substring(6, 2) + " " +
                                                endDate.Substring(8, 2) + ":" + endDate.Substring(10, 2) + ":" + endDate.Substring(12, 2));

            SqlParameter[] paramList = new SqlParameter[] { DbHelper.CreateCommandParameter("@StartDate",SqlDbType.VarChar,startDt),
                                                            DbHelper.CreateCommandParameter("@EndDate",SqlDbType.VarChar,endDt),
                                                            DbHelper.CreateCommandParameter("@BC",SqlDbType.VarChar,bankCode),
                                                            DbHelper.CreateCommandOutParameter("@return",SqlDbType.Int)
                                                           };
            try
            {
                conn = DbHelper.CreateDbConnection(DbHelper.DbConnectionString);
                conn.Open();
                ret = DbHelper.ExecuteNonQueryByProc("NXS_Reconcile", paramList, conn) > 0;
            }
            catch (SqlException ex)
            {
                ret = false;
            }
            finally
            {
                conn.Close();
            }
            return ret;
        }
    }
}
